package com.fau.cm.action.index;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.fau.cm.action.PublicAction;
import com.fau.cm.entity.MedicalAdmin;
import com.fau.cm.entity.MedicalCallContactRecord;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 联系记录Action
 * @author kangyj
 * @datetime 2014年12月4日,下午8:25:21
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class ContactRecordAction extends PublicAction implements
		ModelDriven<MedicalCallContactRecord> {
	
	private static final long serialVersionUID = 847115849359986089L;
	
	private MedicalCallContactRecord contactRecord = new MedicalCallContactRecord();

	/**
	 * @desc 联系记录页面初始化
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月4日,下午8:29:09
	 */
	@Action(value = "contact_record_init", results = {@Result(location = "contact_record_init.jsp")})
	public String init() {
		return SUCCESS;
	}
	
	/**
	 * @desc 查询联系记录数据
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月4日,下午8:26:28
	 */
	@Action(value = "contact_record_view")
	public String view() {
		HttpServletResponse response = ServletActionContext.getResponse();
		list = this.baseAllService.getCustomerService().findContactRecordList(contactRecord.getCustomerId());
		formatJSON(response, list);
		return null;
	}
	
	/**
	 * @desc 保存联系记录
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月4日,下午8:27:54
	 */
	@Action(value = "contact_record_save")
	public String save() {
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		contactRecord.setOperatorId(admin.getId());
		this.baseAllService.getCustomerService().saveContactRecord(contactRecord);
		map.put("success", true);
		formatJSON(response, map);
		return null;
	}
	
	@Override
	public MedicalCallContactRecord getModel() {
		return contactRecord;
	}

}
